﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;
namespace IFRS.DataAccess.DAL
{
    public class SPR_GSBBondInterest
    {
        public DataTable SEARCH_ALL(GSBBondInterest gSBBondInterest, Paging paging, bool IFRS_ALLBRANCH, string sIFRS_COST_CENTER, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@isAllBranch", IFRS_ALLBRANCH));
                lstParams.Add(new SqlParameter("@sCostCenter", sIFRS_COST_CENTER));
                lstParams.Add(new SqlParameter("@GSBBondCode", gSBBondInterest.GSBBondCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@InterestPaymentDate", gSBBondInterest.InterestPaymentDate.AsDBValue()));                        
                lstParams.Add(new SqlParameter("@IsConfirmed", gSBBondInterest.IsConfirmed.AsDBValue()));

                dt = Utility.StoredProcDataTable("SPR_GSBBondInterest_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable SEARCH_BYID(int GSBBondInterestID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@GSBBondInterestID", GSBBondInterestID.AsDBValue()));

                dt = Utility.StoredProcDataTable("SPR_GSBBondInterest_SEARCHBYID", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(GSBBondInterest gSBBondInterest)
        {

            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@GSBBondInterestID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@GSBBondCode", gSBBondInterest.GSBBondCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@InterestPaymentDate", gSBBondInterest.InterestPaymentDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@InterestRate", gSBBondInterest.InterestRate.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", gSBBondInterest.IsConfirmed.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedDate", gSBBondInterest.CreatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBy", gSBBondInterest.CreatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", gSBBondInterest.CreatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBranch", gSBBondInterest.CreatedBranch.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", gSBBondInterest.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", gSBBondInterest.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", gSBBondInterest.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", gSBBondInterest.UpdatedBranch.AsDBValue()));

                Utility.ExecuteStoredProc("SPR_GSBBondInterest_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(GSBBondInterest gSBBondInterest)
        {


            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@GSBBondInterestID", gSBBondInterest.GSBBondInterestID.AsDBValue()));
                lstParams.Add(new SqlParameter("@GSBBondCode", gSBBondInterest.GSBBondCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@InterestPaymentDate", gSBBondInterest.InterestPaymentDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@InterestRate", gSBBondInterest.InterestRate.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", gSBBondInterest.IsConfirmed.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", gSBBondInterest.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", gSBBondInterest.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", gSBBondInterest.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", gSBBondInterest.UpdatedBranch.AsDBValue()));

                iNum = (int)Utility.ExecuteStoredProc("SPR_GSBBondInterest_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(GSBBondInterest gSBBondInterest)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@GSBBondInterestID", gSBBondInterest.GSBBondInterestID.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", gSBBondInterest.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", gSBBondInterest.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", gSBBondInterest.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", gSBBondInterest.UpdatedBranch.AsDBValue()));

                iNum = (int)Utility.ExecuteStoredProc("SPR_GSBBondInterest_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
    }
}
